package edu.hwadee.serviceImpl;

import java.util.List;

import edu.hwadee.entity.Officematerialbuy;
import edu.hwadee.service.OfficematerialbuyService;

public class OfficematerialbuyServiceImpl extends BasicServiceImpl implements OfficematerialbuyService {

	@Override
	public boolean save(Officematerialbuy officematerialbuy) {
		try {
			getOfficematerialbuyDAO().save(officematerialbuy);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean delete(Officematerialbuy officematerialbuy) {
		try {
			getOfficematerialbuyDAO().delete(officematerialbuy);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Officematerialbuy> search(Officematerialbuy officematerialbuy) {
		try {
			return (List<Officematerialbuy>)getOfficematerialbuyDAO().findByExample(officematerialbuy);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Officematerialbuy searchById(Integer officematerialbuyId) {
		try {
			return getOfficematerialbuyDAO().findById(officematerialbuyId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean update(Officematerialbuy officematerialbuy) {
		try {
			if(searchById(officematerialbuy.getOfficematerialBuyId()) != null) {
				getOfficematerialbuyDAO().merge(officematerialbuy);
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Officematerialbuy> showAll() {
		try {
			return (List<Officematerialbuy>)getOfficematerialbuyDAO().findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
